home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000095_icon-group-sender_Tue Oct 24 08:18:24 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9OFI8B14452
  4.     for icon-group-addresses; Tue, 24 Oct 2000 08:18:08 -0700 (MST)
  5. Message-Id: <200010241518.e9OFI8B14452@baskerville.CS.Arizona.EDU>
  6. From: "Jay Hammond" <J.Hammond@qmw.ac.uk>
  7. To: icon-group@cs.arizona.edu
  8. Date: Tue, 24 Oct 2000 10:49:48 +0000
  9. Subject: re: simple - can't index a string
  10. X-Confirm-Reading-To: J.Hammond@qmw.ac.uk
  11. X-pmrqc: 1
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: RO
  14. Content-Length: 3066
  15.  
  16.  
  17. > Greetings:
  18. > Another question that "should" be simple....but I can't seem to figure
  19. > it out.
  20. > I have the statement....
  21. > UPPER[index]  := &ucase[find(data[index],&lcase)]
  22. > ....which is giving an error:
  23. > Traceback:
  24. >    main()
  25. >    {(variable = &null)[1]} from line 8 in noname.icn
  26. > best I can tell, it is choking because UPPER has not been "declared".
  27. > But I can't find anywhere how to "declare" a string. In fact, all the
  28. > references I find talk about how ICON doesn't NEED "declarations" 
  29. in the
  30. > traditional sense of a programming language. Soooo...uhhh....???
  31. Perhaps I have a solution to the first part;
  32.  
  33. First off, the bald solution:
  34.  
  35. Don't declare the string to have type "string", just create a 
  36. suitable string.  
  37.  
  38. and some words of explanation;
  39. If I may approach this problem from the side, by 
  40. thinking about what is going wrong, 
  41. suppose the INDEX to UPPER was 5
  42. (I know your error message said it evaluated to 1)
  43. then you'd be looking at the thing at position 5 in UPPER.
  44. Any programming  language will have a hard 
  45. time locating position 5 in a string that does not exist. 
  46. You have said that UPPER  does not exist yet.
  47. At best, you could expect a request to index into UPPER to 
  48. "default" to creating a string of  ... err what would it be? Ascii nulls,
  49. Blanks, something  long enough to resolve your reference, and return the
  50. relevant part of your default string.  - so in my example you'd get the
  51. 5th blank (or whatever)  along. In my opinion, it is more use to you as a
  52. programmer to be told
  53.  
  54. There's no such string as UPPER, so it's getting you nowhere to 
  55. look at position 5 in it.
  56.  
  57. You don't have to declare UPPER before you use it, and the type, 
  58. when you do use it, will be figured out for you. 
  59. I propose 
  60. UPPER := "a suitable string for your purpose"
  61.  
  62. I have had a similar problem; I have tried
  63.  
  64. while (......) do {
  65.   i +:= 1
  66. ....
  67. }
  68.  
  69. and wondered why I get errors incrementing i
  70. It turns out that i had no value earlier, and unlike Snobol,
  71. that absence of a value does not convert to a numeric zero.
  72. I have to write 
  73. i := 0 
  74. before the loop construct, 
  75. (or whatever starting value my loop needs)
  76.  
  77. You can't increment nothing, but you can increment from zero.
  78. You can't index into a string that's not there.  
  79.  Don't declare the string, create it!
  80.  
  81. I think, if you request an index that is off the end of a string,
  82. you just get  a graceful fail, that might let you backtrack or resume. so
  83. animal := "cat"             # I just got Icon to make me a string if
  84. animal[5] then write("cat o' nine tails") else write("manx")
  85.  
  86. should always write "manx" 
  87.  
  88. (non-brits; there is a pun here
  89. cat o' nine tails is an  whip with 9 thongs (naval, historical)
  90. a manx cat is one from the isle of man, a breed with no tail to speak of
  91. <I hope that is not because they are docked>)
  92.  
  93. [snipped 2ndary question already answered better than I could]
  94. all the best, Jay
  95.  
  96.  
  97.  
  98. Jay Hammond,                        Email j.hammond@qmw.ac.uk
  99. Arts Computing Unit
  100. Queen Mary & Westfield College,
  101. Mile End Rd, London E1 4NS
  102. Phone +44 20 7882 3209
  103.